urlbox_default = "click to paste url here";
window.onload = function () {
	// add event to url
	var urlbox = document.getElementById('url');
		if (urlbox) {
		urlbox.onfocus = function () {
			this.className = '';
			if (this.value == urlbox_default) {
				this.value = "http://";
				this.select();
			}
		}
		urlbox.onblur = function () {
			if (this.value == "" || this.value == "http://" || this.value == urlbox_default) {
				this.value = urlbox_default
				this.className = 'empty';
			}
		}
		if (urlbox.value == "") {
			urlbox.onblur();
		} else {
			urlbox.onfocus();
		}
	}
	var urlteaform = document.getElementById('urlteaform');
	if (urlteaform) {
		urlteaform.onsubmit = function () {
			urlbox = document.getElementById('url');
			if (urlbox && (urlbox.value == "" || urlbox.value == urlbox_default || urlbox.value == 'http://')) {
				errorbox = document.getElementById('urlteaform_error');
				errorbox.innerHTML = "I can only shorten valid URLs,<br /> e.g.: <code>http://www.example.com/example/</code><br />... Try again.";
				errorbox.className = "error";
				return false;
			}
		}
	}
	var copyurl = document.getElementById('copyurl');
		if (copyurl) {
		copyurl.onclick = function() {
			copy(document.getElementById('urltea'));
		}
	}
	var urltea = document.getElementById('urltea');
	if (urltea) {
		copy(document.getElementById('urltea'));
		document.getElementById('copiedtoclipboard').innerHTML = "Your shortened URL is in your clipboard, ready for pasting :)<br />";
		document.getElementById('copyurl').innerHTML = "oops, " + document.getElementById('copyurl').innerHTML + " again";
		document.getElementById('clipboardtools').className = "";
	}
}

function copy(inElement) {
	// thanks to http://www.jeffothy.com/weblog/clipboard-copy/
  if (inElement.createTextRange) {
    var range = inElement.createTextRange();
    if (range && BodyLoaded==1)
     range.execCommand('Copy');
  } else {
    var flashcopier = 'flashcopier';
    if(!document.getElementById(flashcopier)) {
      var divholder = document.createElement('div');
      divholder.id = flashcopier;
      document.body.appendChild(divholder);
    }
    document.getElementById(flashcopier).innerHTML = '';
    var divinfo = '<embed src="_clipboard.swf" FlashVars="clipboard='+escape(inElement.value)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
    document.getElementById(flashcopier).innerHTML = divinfo;
  }
}

